﻿namespace ZenSystemService.Api.Common
{
    public static class EnumsHelper
    {
        /// <summary>
        /// 获取描述信息 [DescriptionAttribute]
        /// </summary>
        public static string GetDesc(this Enum value)
        {
            try
            {
                var field = value.GetType().GetField(value.ToString());
                var attribute = Attribute.GetCustomAttribute(field, typeof(System.ComponentModel.DescriptionAttribute))
                            as System.ComponentModel.DescriptionAttribute;

                return attribute == null ? value.ToString() : attribute.Description;
            }
            catch { return "?"; }
        }
    }
}
